using UnityEngine;

public class BackControl : MonoBehaviour
{
    public float speed = 2.0f;

    public Transform background1;

    public Transform background2;

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        // 移动background1 background2
        background1.Translate(Vector3.down * speed * Time.deltaTime);
        background2.Translate(Vector3.down * speed * Time.deltaTime);
        //如果超出-8.52f 换到另一个上面
        if (background1.position.y < -8.52f)
        {
            background1.position = new Vector3(background2.position.x, background2.position.y + 8.25f,
                background2.position.z);
        }

        if (background2.position.y < -8.52f)
        {
            background2.position = new Vector3(background1.position.x, background1.position.y + 8.25f,
                background1.position.z);
        }
    }
}